package com.usefullc.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.demo.domain.Demo;
import com.usefullc.demo.mapper.DemoMapper;
import com.usefullc.demo.query.DemoQuery;
import com.usefullc.demo.vo.DemoVo;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.service.AbstractBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 *
 * @author: Sampson
 * @date: 2018-12-19 16:05
 */
@Service
public class DemoService extends AbstractBizService<DemoMapper, Demo, DemoQuery> {



    @Override
    protected QueryWrapper<Demo> getQueryWrapper(DemoQuery query) {
        QueryWrapper<Demo> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }

    public Pager<DemoVo> findVoByPage(DemoQuery query){
        Pager<Demo> page = this.findByPage(query);
        Pager<DemoVo> newPage = new Pager<>(page);
        List<Demo> dataList = page.getDataList();
        List<DemoVo> newDataList = new ArrayList<>();
        newPage.setDataList(newDataList);
        for (Demo demo : dataList) {
            DemoVo demoVo = BeanUtils.beanCopy(demo, DemoVo.class);
            newDataList.add(demoVo);
        }
        return newPage;
    }


}
